package com.yiyi.credit.manage.sso.mapper;


import com.yiyi.credit.manage.sso.common.constants.PaginationConstants;
import com.yiyi.credit.manage.sso.common.page.PageUtils;

import java.util.Map;


public class SysResourceSqlProvider {

    //查询表
    private String fromInfo = " from sys_role_resource so left join sys_resource sr on sr.id = so.sys_resource_id ";


    public String queryResourceForPage(Map<String, Object> paramMap) {
        //查询字段
        String selectFiled = " so.sys_resource_id as id,so.pid,sr.name ";

        return PageUtils.getPageCommonSql(selectFiled, fromInfo, whereSql(paramMap), "id")
                + PaginationConstants.LIMIT_SQL;
    }


    public String queryResourceCount(Map<String, Object> paramMap) {
        //查询条数
        String countFiled = " count(so.sys_resource_id) count ";
        return PageUtils.getPageCountSql(countFiled, fromInfo, whereSql(paramMap));
    }


    private String whereSql(Map<String, Object> paramMap) {
        StringBuilder sqlBuilder = new StringBuilder();
        sqlBuilder.append(" WHERE 1 = 1 ");
        if (null != paramMap.get("sysInfoId")) {
            sqlBuilder.append(" AND so.sys_info_id = #{sysInfoId} ");
        }
        if (null != paramMap.get("sysRoleId")) {
            sqlBuilder.append(" AND so.sys_role_id = #{sysRoleId} ");
        }
        if (null != paramMap.get("pid")) {
            sqlBuilder.append(" AND so.pid = #{pid} ");
        }
        return sqlBuilder.toString();
    }

}
